package com.hero.take.util;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description
 * @Author liboo
 * @Data 2023/3/8 14:01
 */
public class RegularExpressionUtils {


    /**
     * 提取车牌号
     *
     * @param text
     * @return
     */
    public static List<String> extractVehicleNo(String text) {
        List<String> mappers = new ArrayList<>();
        String CarNumberVerify = "([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}(([A-HJ-Z]{1}[A-HJ-NP-Z0-9]{5})|([A-HJ-Z]{1}(([DF]{1}[A-HJ-NP-Z0-9]{1}[0-9]{4})|([0-9]{5}[DF]{1})))|([A-HJ-Z]{1}[A-D0-9]{1}[0-9]{3}警)))|([0-9]{6}使)|((([沪粤川云桂鄂陕蒙藏黑辽渝]{1}A)|鲁B|闽D|蒙E|蒙H)[0-9]{4}领)|(WJ[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼·•]{1}[0-9]{4}[TDSHBXJ0-9]{1})|([VKHBSLJNGCE]{1}[A-DJ-PR-TVY]{1}[0-9]{5})";
        Pattern pattern = Pattern.compile(CarNumberVerify);
        Matcher matcher = pattern.matcher(text);
        StringBuilder bf = new StringBuilder();
        while (matcher.find()) {
            mappers.add(matcher.group());
        }
        int len = bf.length();
        if (len > 0) {
            bf.deleteCharAt(len - 1);
        }
        //去空
        mappers.removeIf(Objects::isNull);
        System.out.println(JSONObject.toJSONString(mappers));
        return mappers;
    }


}
